package com.sjsu.cloudmanager.client.ui;

import com.extjs.gxt.ui.client.Style;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.RowData;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.google.gwt.user.client.Element;
import com.sjsu.cloudmanager.client.ui.model.CloudLabBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: ckempaiah
 * Date: 9/23/11
 * Time: 1:01 AM
 * To change this template use File | Settings | File Templates.
 */
public class LabGridStore extends LayoutContainer {


    @Override
    protected void onRender(Element parent, int index) {
        super.onRender(parent, index);
        setBorders(false);
        ContentPanel cp = new ContentPanel();
         //setStyleAttribute("margin", "10px");

         cp.setFrame(true);
         cp.setHeight(400);
         cp.setHeaderVisible(false);
         cp.setLayout(new RowLayout(Style.Orientation.HORIZONTAL));
         cp.setBorders(false);
        List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
        ColumnConfig cc1 = new ColumnConfig("labName", "Lab Name", 80);
        ColumnConfig cc2 = new ColumnConfig("labStatus", "Lab Status", 80);

        configs.add(cc1);
        configs.add(cc2);


        ListStore<CloudLabBean> store = new ListStore<CloudLabBean>();
        store.setMonitorChanges(true);
        store.add(getLabInfo());

        ColumnModel cm = new ColumnModel(configs);

        Grid<CloudLabBean> grid = new Grid<CloudLabBean>(store, cm);
        grid.getView().setEmptyText("sdfd");
        grid.setBorders(false);
        grid.setAutoExpandColumn("labName");
        cp.add(grid, new RowData(1, 1));

        add(cp);
        setLayout(new FitLayout());
        //setSize(800,400);

    }

    private List<CloudLabBean> getLabInfo(){
        List<CloudLabBean> labBeanList = new ArrayList<CloudLabBean>();
        CloudLabBean cloudLabBean = new CloudLabBean();
        cloudLabBean.setLabName("lab1");
        cloudLabBean.setLabStatus("saved");
        labBeanList.add(cloudLabBean);

        cloudLabBean = new CloudLabBean();
        cloudLabBean.setLabName("lab2");
        cloudLabBean.setLabStatus("saved");
        labBeanList.add(cloudLabBean);

        cloudLabBean = new CloudLabBean();
        cloudLabBean.setLabName("lab3");
        cloudLabBean.setLabStatus("saved");
        labBeanList.add(cloudLabBean);

        cloudLabBean = new CloudLabBean();
        cloudLabBean.setLabName("lab4");
        cloudLabBean.setLabStatus("saved");
        labBeanList.add(cloudLabBean);

        cloudLabBean = new CloudLabBean();
        cloudLabBean.setLabName("lab5");
        cloudLabBean.setLabStatus("saved");
        labBeanList.add(cloudLabBean);

        cloudLabBean = new CloudLabBean();
        cloudLabBean.setLabName("lab6");
        cloudLabBean.setLabStatus("saved");
        labBeanList.add(cloudLabBean);

        return  labBeanList;

    }
}
